import Frame from "./main/frame"
import tools from "./tools"
import Conn from "./main/conn"

tools.getView().isMaximizable = false
/**
 * 窗口创建时聚焦，并移动到中间
 */
!(() => {
    const scale = devicePixelRatio
    const [w, h] = tools.workAreaSize()
    const width = 1024 * scale
    const height = 634 * scale
    tools.getView().move(w / 2 - width / 2, h / 2 - height / 2, width, height)
    tools.focus()
})()
document.onready = () => {
    /**
     * 禁用窗口关闭
     */
    document.on("closerequest", evt => {
        evt.preventDefault()
        tools.windowHide()
    })

    /**
     * 载入连接列表
     */
    document.$("#conn-list").patch(<Conn/>)
    document.$("#frame").patch(<Frame/>)

    /**
     * 监听其他页面发来的显示主窗口事件
     */
    document.onGlobalEvent("show-main", evt => {
        tools.windowShow()
        tools.focus()
    })

    /**
     * 关闭按钮点击事件
     */
    document.on("click", "#exit", () => {
        tools.windowHide()
    })

    document.on("click", "#refresh", () => {
        document.post(new Event("refresh"))
    })
}